/**
 * Controller File 
 * @author zmx@gootop.net
 * @version  GMW 0.1
 * @date 2011-3-30
 */
//定义命名空间
GM = {};
GM.RootScript = GM.rootUrl=jQuery('base').attr('href');

FB = {};
FB.p = {};
FB.f = {};
FB.p.styleStr = '<style type="text/css">.i_e_6{margin:0 auto;background:#f00;width:950px;height:80px;padding-left:20px;font-size:12px;color:#fff;font-family:"微软雅黑", "黑体";z-index:999;}';
FB.p.styleStr+= '.i_e_6 a{color:#fff;}.i_e_6 div{line-height:30px;font-size:15px;}.i_e_6 p{margin:7px 0;line-height:18px;}</style>';
FB.p.htmlStr = '<div class="i_e_6"><div>您正在使用不安全的浏览器！</div><p>似乎您正在使用的 <a href="http://www.microsoft.com/windows/internet-explorer/" target="_blank">Internet Explorer</a> 版本不安全。使用过时的浏览器会降低您计算机的安全性。同时，为了获得最佳上医网体验，请升级您的浏览器。<Br />';
FB.p.htmlStr+= '升级 <a href="#">Internet Explorer</a>，或访问 <a href="http://browsehappy.com/" target="_blank">Browse Happy</a> 网站来了解如何获得最佳浏览体验。</p></div>';
FB.f.addTip = function(){
	jQuery().ready(function(){
		jQuery('body').prepend(FB.p.styleStr+FB.p.htmlStr);
	});
};
if ( jQuery.browser.msie ){
	if( jQuery.browser.version == '6.0'){
		FB.f.addTip();
	};
};

//pop菜单
GM.pop =function(posTar,msg,type,fixTop,fixLeft){
  	posTar.focus();
  	var position = posTar.offset();
  	var pop = '<div id=\'pop_tip\' class = "'+(type?'pop_true':'pop_false')+'" style = \'position:fixed;top:'+Number(position.top-fixTop)+'px;left:'+Number(position.left-fixLeft)+'px;display:none;\'>'+msg+'</div>';
  	jQuery('body').append(pop);
  	jQuery('#pop_tip').fadeIn(300);
  	posTar.blur(function(){
  		GM.pop_remove();
  	});
};

GM.pop_remove = function(){
	jQuery('#pop_tip').remove();
};

$().ready(function(){
	$('#content').scroll(function(){
		GM.pop_remove();
	});
	$('img').on('error',function(){
		//$(this).attr('src',GM.RootScript +'/img/ucenter/patient.jpg');
	});
});

GM.tip = function(msg,type){
	jQuery("#gm_tip").remove();
	var tip = '<div id=\'gm_tip\' class = "'+(type?'success':'error error_tip')+'" style = \'position:fixed;display:none\'>'+msg+'</div>';
	$('body').append(tip);
	var width = jQuery(window).width();
	var height = jQuery(window).height();
	jQuery("#gm_tip")
		.css({
			'z-index':9999,
			'border':'1px solid #ccc',
			'background-color':'#FFF',
			'top':height/2-50,
			'left':width/2-150})
			.fadeIn(800);
	setTimeout("GM.hideTips()",3000);	
};
GM.hideTips = function(){
	jQuery("#gm_tip").fadeOut(500,function(){$(this).remove();});
};

GM.ask = function(){
	if($('#main_key').val() == ''){
		$('#main_key').effect('highlight');
		return false;
	}
	$("#main_ask").submit();
};


GM.confirm = function(options){
	var def = {
	      autoOpen: true,
	      height: 150,
	      width: 350,
	      modal: true,
	      title:'',
	      msg : '',
	      resizable:false,
	      buttons: {
	    	  "确定": function() {$( this ).dialog( "close" );options.func();},
	    	  "取消": function() {$( this ).dialog( "close" );}
		  },
		  close: function() {
			  $( "#dialog-confirm-form").remove();
		  }
	  };
	var config = jQuery.extend(def,options);
	$('body').append("<div id = 'dialog-confirm-form'><p>"+config.msg+"</p></div>");
	$( "#dialog-confirm-form" ).dialog(config);
};

GM.placeholder = function(tar){
	var type = tar.attr('type');//文本框类型
	if(!('placeholder' in document.createElement('input'))){
		if(type == 'text'){
			var placeholder_value = tar.attr('placeholder');
    		tar.removeAttr("placeholder").val(placeholder_value).bind("focus",function(){
    			if (this.value == placeholder_value){
    				this.value="";
    			};
    		}).bind("blur",function(){
    			if (this.value == ""){
    				this.value=placeholder_value;
    			};
    		});
		}else if(type == 'password'){
			//对password框的特殊处理1.创建一个text框 2获取焦点和失去焦点的时候切换
			var pwdVal		= tar.attr('placeholder');
			tar.after('<input id="pwdPlaceholder" type="text" value='+pwdVal+' autocomplete="off" />');
			var pwdPlaceholder = $('#pwdPlaceholder');
			pwdPlaceholder.show();
			tar.hide();
			
			pwdPlaceholder.focus(function(){
				pwdPlaceholder.hide();
				tar.show();
				tar.focus();
			});
		        
			tar.blur(function(){
				if(tar.val() == '') {
					pwdPlaceholder.show();
					tar.hide();
				}
			});
		}else{
		}
	}
};

GM.shareHander = false;
GM.share = function(){
	clearTimeout(GM.shareHander);
	GM.shareHander = setTimeout(GM.baiduShare,1000);
};
GM.baiduShare = function(){
	bdShare.fn.init();
};

GM.switchSite = function(target){
	location.href = GM.rootUrl+'admin/SysWebsites/switch/'+target.value;
}
